﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HFController;

namespace HFWebManage.Legislation
{
    public partial class LegislationList : HFController.BagePages
    {
        /// <summary>
        /// 法规列表
        /// </summary>
        public List<hf.Model.Legislation> list = new List<hf.Model.Legislation>();
        protected void Page_Load(object sender, EventArgs e)
        {
            string PageStr = "";
            list = LegislationController.getController().getLegislationList(out PageStr);
            pager.Text = PageStr;

            string Action = this.GetQuery("action");
            switch (Action)
            {
                case "delete": //单个删除
                    int ID = int.Parse(this.GetQuery("ID"));
                    LegislationController.getController().doDelegeLegislation(ID);
                    break;
                case "deleteall": //批量删除
                    string IDS = this.GetAll("cid1");
                    LegislationController.getController().doDelegeLegislation(IDS.Split(','));
                    break;
                case "seach":
                    string keys = this.GetQuery("keys");
                        int total = 0;
                        int PageNumber = 1;
                        list = LegislationController.getController().getLegislationList(10, 1, "Title like '%" + keys + "%'", out total);
                        if (this.GetQuery("Page") != "")
                        {
                            PageNumber = int.Parse(this.GetQuery("Page"));
                        }
                        pager.Text = LLL.Pager.TrunPageHtmlCode(10, PageNumber, total, "");
                    break;
            }
        }

        /// <summary>
        /// 获得法规库名称
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public string getLegislationLibaryName(int ID)
        {
            hf.Model.LegislationLibary model = LegislationController.getController().getLegislationLibaryModel(ID);
            //return model.LegislationLibaryName;
            if (model != null)
            {
                return model.LegislationLibaryName;
            }
            else
            {
                return "";
            }
        }
        /// <summary>
        /// 获得法规类名称
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public string getClassName(int ID)
        {
            hf.Model.LegislationClass model = LegislationController.getController().getLegislationClassModel(ID);
            //return model.ClassName;
            if (model != null)
            {
                return model.ClassName;
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 关键字搜索
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button4_Click(object sender, EventArgs e)
        {
            Response.Redirect("LegislationList.aspx?action=seach&keys=" + keys.Text);
        }
    }
}